<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>02_json</title>
	<meta name="author" content="Stark" />
	<!-- Date: 2018-10-19 -->
	<script type="text/javascript">
		/**
		 * json的意思就是javascript simple object notation
		 * json就是js的对象，但是他省去了xml中的标签，而是通过{}来完成对象的说明
		 */
		var person = {
			name:"张三",	// 通过属性名:属性值来表示，不同属性通过,来间隔
			age:23,
			say:function(){
				alert(this.name+","+this.age);
			}	// 最后一个属性之后不能有,
		}
		
		person.say();
		/**
		 * 通过json依然可以创建对象数组，创建方式和js的数组一样
		 */
		var ps = [
			{name:"leno",age:22},
			{name:"Ada",age:33}
		];
		for(var i=0;i<ps.length;i++){
			alert(ps[i].name);
		}
		/**
		 * 创建一组用户，用户的属性有
		 * name:string,age:int,friends:array
		 * List<Person> ps = new ArrayList<>();
		 * ps.add(new Person("Leno",22,["Ada","Alice"]));
		 * ps.add(new Person("John",33,["Ada","Chris"]));
		 * 把ps转换为json
		 */
		var ps1 = [
			{
				name:"Leno",
				age:22,
				friends:["Ada","Alice"]
			},
			{
				name:"John",
				age:33,
				friends:["Ada","Chris"]
			}
		];
		for(var i=0;i<ps1.length;i++) {
			alert(ps1[i].name+","+ps1[i].age+","+ps1[i].friends);
		}
	</script>
</head>
<body>

</body>
</html>

